package com.xes.apps.ams.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.xes.ams.client.api.AttendData;
import com.xes.ams.client.api.AttendResult;
import com.xes.ams.client.api.AttendVo;
import com.xes.ams.client.api.BaseException;
import com.xes.ams.client.api.Result;
import com.xes.ams.client.api.ResultCode;
import com.xes.apps.ams.client.core.service.AttendDataDao;
import com.xes.apps.ams.client.core.service.AttendDataService;
import com.xes.apps.ams.config.ServerConfig;

@RestController
@RequestMapping("/admin")
public class AdminController {

	private static final Logger log = LogManager.getLogger(AdminController.class);
	@Inject
	private ServerConfig config;
//	@Inject
//	private AttendDataDto attendDataDto;

	@RequestMapping("/view")
	public String view() {
		log.info("AdminController is view {}", "info");
		return "system is very healthy";
	}
	
	@RequestMapping("/query/config")
	public Result<ServerConfig> Config() {
		Result<ServerConfig> result = new Result<>();
		result.setData(config);
		result.setSuccess(true);
		result.setCode(ResultCode.SUCCESS.getCode());
		result.setMessage(ResultCode.SUCCESS.getMessage());
		return result;
	}

//	@RequestMapping("/query/attenddata")
//	public Result<Iterable<AttendData>> queryAttendData() throws BaseException {
//		Iterable<AttendData> dataList = attendDataDto.findAll();
//
//		Result<Iterable<AttendData>> result = new Result<>();
//		if (null != dataList) {
//			result.setSuccess(true);
//			result.setCode(ResultCode.SUCCESS.getCode());
//			result.setMessage(ResultCode.SUCCESS.getMessage());
//			result.setData(dataList);
//		} else {
//			result.setSuccess(false);
//			result.setCode(ResultCode.ERROR.getCode());
//			result.setMessage(ResultCode.ERROR.getMessage());
//			result.setData(dataList);
//		}
//		return result;
//	}
//
//	@RequestMapping("/query/attendcount")
//	public Result<Map<String, Integer>> queryAttendCount() throws BaseException {
//		Result<Map<String, Integer>> reult = new Result<>();
//		Map<String, Integer> attendDataCount = new HashMap<String, Integer>();
//		Iterable<AttendData> iter = attendDataDto.findAll();
//
//		List<AttendData> dataList = Lists.newArrayList();
//		while(iter.iterator().hasNext()) {
//			dataList.add(iter.iterator().next());
//		}
//
//		int total = (int) dataList.stream().filter(att -> att.getIsDelete() == 0).count();
//		int noattend = (int) dataList.stream().filter(att -> att.getIsDelete() == 0)
//				.filter(att -> att.getIsAbsent() == 1).count();
//		int nopunctual = (int) dataList.stream().filter(att -> att.getIsDelete() == 0)
//				.filter(att -> att.getIsAbsent() == 0).filter(att -> att.getIsPunctual() == 1).count();
//
//		attendDataCount.put("total", total);
//		attendDataCount.put("noattend", noattend);
//		attendDataCount.put("nopunctual", nopunctual);
//
//		reult.setSuccess(true);
//		reult.setCode(ResultCode.SUCCESS.getCode());
//		reult.setMessage(ResultCode.SUCCESS.getMessage());
//		reult.setData(attendDataCount);
//
//		return reult;
//	}
}
